<template>
	<view class="content">
		<div class="img">
			<image src="../../static/ranking/排行榜顶图@2x.png" mode="widthFix"></image>
		</div>
		<div class="box">
			<div class="top">
				<div class="t">
					<div class="img">
						<image src="../../static/ranking/2框.png" mode="widthFix"></image>
						<image src="../../static/ranking/2@2x.png" mode="widthFix"></image>
						<image :src="two.avatar" mode="scaleToFill" class="avatar"></image>
					</div>
					<div class="img">
						<image src="../../static/ranking/1框@2x.png" mode="widthFix"></image>
						<image src="../../static/ranking/1@2x.png" mode="widthFix"></image>
						<image :src="one.avatar" mode="scaleToFill" class="avatar"></image>
					</div>
					<div class="img">
						<image src="../../static/ranking/3框.png" mode="widthFix"></image>
						<image src="../../static/ranking/3@2x.png" mode="widthFix"></image>
						<image :src="three.avatar" mode="scaleToFill" class="avatar"></image>
					</div>
				</div>
				<div class="b">
					<div class="li">
						<div class="name">{{ two.name }}</div>
						<div class="text">截至今天</div>
						<div class="money">{{ two.amountCont | formatDecimal}}元</div>
					</div>
					<div class="li">
						<div class="name">{{ one.name }}</div>
						<div class="text">截至今天</div>
						<div class="money">{{ one.amountCont | formatDecimal}}元</div>
					</div>
					<div class="li">
						<div class="name">{{ three.name }}</div>
						<div class="text">截至今天</div>
						<div class="money">{{ three.amountCont | formatDecimal}}元</div>
					</div>
				</div>
			</div>
			<scroll-view v-if="ranking.length >= 1" class="scroll" scroll-y="true">
				<div class="li" v-for="(bh,index) in ranking">
					<div class="num">{{index + 4}}</div>
					<image :src="bh.avatar" mode="widthFix"></image>
					<p class="name">{{ bh.name }}</p>
					<div class="text">截至今天</div>
					<div class="money">{{ bh.amountCont | formatDecimal}}元</div>
				</div>
			</scroll-view>
			<div class="li bottom">
				<div class="num">{{ myPosition }}</div>
				<image :src="my.avatar" mode="widthFix"></image>
				<p class="name">{{ my.name }}</p>
				<div class="text">截至今天</div>
				<div class="money">{{my.amountCont | formatDecimal}}元</div>
			</div>
		</div>
	</view>
</template>

<script>
	import Api from "../../API/api";
	export default {
		data() {
			return {

				ranking: [{
					name: "暂无",
					avatar: "../../static/ranking/椭圆形@2x.png",
					amountCont: 0.00
				}],
				one: {
					name: "暂无",
					avatar: "../../static/ranking/椭圆形@2x.png",
					amountCont: 0.00
				},
				two: {
					name: "暂无",
					avatar: "../../static/ranking/椭圆形@2x.png",
					amountCont: 0.00
				},
				three: {
					name: "暂无",
					avatar: "../../static/ranking/椭圆形@2x.png",
					amountCont: 0.00
				},
				my: {},
				myPosition: null
			}
		},
    filters: {
      formatDecimal(value) {
        // 将值转换为 Number 类型，然后使用 toFixed 方法将其格式化为带有两位小数的字符串
        return Number(value).toFixed(2);
      },
    },
		onLoad() {
			Api.getLeaderboard().then(res => {
				console.log(res.data)
				if (res.data.ranking[0]) {
					this.one = res.data.ranking[0]
				}
				if (res.data.ranking[1]) {
					this.two = res.data.ranking[1];
				}
				if (res.data.ranking[2]) {
					this.three = res.data.ranking[2];
				}
				if (res.data.ranking.length > 2) {
					let arr = res.data.ranking.splice(3)
					this.ranking = arr;
				}
				this.my = res.data.rankingOne;
				this.myPosition = res.data.myPosition;
				console.log(arr)
			})
		},
		methods: {

		}
	}
</script>

<style lang="less" scoped>
	.content {
		height: 100vh;
		width: 100%;
		overflow: hidden;
		position: fixed;
		top: 0;

		.img {
			position: relative;


			image {
				width: 100%;

			}
		}
		.avatar{
			
			
			
		}

		.box {
			position: relative;
			width: 90%;
			height: calc(100vh - 350rpx);
			box-shadow: 0rpx 16rpx 16rpx 2rpx rgba(61, 74, 113, 0.06);
			border-radius: 20rpx;
			backdrop-filter: blur(4px);
			margin: auto;
			box-sizing: border-box;
			transform: translateY(-140rpx);
			background: rgba(255, 255, 255, 0.7);
			padding: 20rpx;

			image {
				width: 110rpx;
				border-radius: 50%;
			}

			.top {
				padding: 10rpx;
				margin-top: 60rpx;
				display: flex;
				justify-content: space-between;
				text-align: center;
				flex-wrap: wrap;
				align-items: center;

				.t {
					display: flex;
					justify-content: space-around;
					height: 110rpx;
					width: 100%;

					.img {
						position: relative;
						width: 110rpx;
						h: 110rpx;

						&:nth-child(2) {
							width: 150rpx;

							image {
								transform: translateY(-50rpx);
								height: 132rpx;
								&:nth-child(1) {
									top: 0;
									left: 0;
									width: 160rpx;
								}

								&:nth-child(3) {
									top: 25rpx;
									left: 7rpx;
									width: 130rpx;
								}

								&:nth-child(2) {
									bottom: -50rpx;
									right: -5rpx;
									z-index: 10;
									width: 55rpx;
								}
							}
						}

						image {
							position: absolute;height: 100rpx;

							&:nth-child(1) {
								top: 0;
								left: 0;
								width: 110rpx;
							}

							&:nth-child(3) {
								top: 6rpx;
								left: 6rpx;
								width: 100rpx;
							}

							&:nth-child(2) {
								bottom: 0;
								right: -15rpx;
								z-index: 10;
								width: 40rpx;
							}
						}
					}
				}

				.b {
					width: 100%;
					display: flex;
					justify-content: space-around;

					.li {
						width: 150rpx;

						.name,.money {
							width: 150rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						&:nth-child(2) {
							width: 150rpx;
						}
					}
				}

				.name {
					font-weight: 700;
					margin-top: 20rpx;
				}

				.text {
					color: #aaa;
					font-size: 14rpx;
					margin-top: 5rpx;
				}

				.money {
					font-size: 36rpx;
					font-weight: bold;
					color: #FD9509;
				}

				.li {
					&:nth-child(2) {

						image {
							width: 150rpx;
							border-radius: 50%;
						}
					}
				}
			}

			.scroll {
				// border: 1px solid #000;
				max-height: calc(50%);

				.li {
					position: relative;
					display: flex;
					justify-content: start;
					align-items: center;
					padding: 20rpx;
					height: 25px;

					image {
						width: 64rpx;
						border-radius: 50%;
						margin-left: 20rpx;
						height: 64rpx;
						overflow: hidden;
						border: 1px solid #eee;
					}

					.name {
						font-weight: 600;
						max-width: 180rpx;
						font-size: 28rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
						margin-left: 20rpx;
					}

					.text {
						color: #aaa;
						font-size: 16rpx;
						position: absolute;
						right: 130rpx;
					}

					.money {
						font-size: 28rpx;
						font-weight: bold;
						color: #FD9509;
						position: absolute;
						right: 0;
					}

				}
			}


			.bottom {
				display: flex;
				justify-content: start;
				align-items: center;
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				box-sizing: border-box;
				height: 100rpx;
				background: rgba(255, 189, 87, 0.1);
				border-radius: 0rpx 0rpx 20rpx 20rpx;

				image {
					width: 64rpx;
					border-radius: 50%;
					margin-left: 20rpx;
				}

				.num {
					margin-left: 10rpx;
				}

				.name {
					font-weight: 600;
					max-width: 120rpx;
					font-size: 28rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					margin-left: 20rpx;
				}

				.text {
					color: #aaa;
					font-size: 16rpx;
					position: absolute;
					right: 130rpx;
					right: 100px;
					;
				}

				.money {
					font-size: 28rpx;
					font-weight: bold;
					color: #FD9509;
					position: absolute;
					right: 10rpx;
				}
			}

			// .top {
			// 	padding: 10rpx;
			// 	margin-top: 60rpx;
			// 	display: flex;
			// 	justify-content: space-between;
			// 	text-align: center;

			// 	.name {
			// 		font-weight: 700;
			// 		margin-top: 20rpx;
			// 	}

			// 	.text {
			// 		color: #aaa;
			// 		font-size: 16rpx;
			// 		margin-top: 5rpx;
			// 	}

			// 	.money {
			// 		font-size: 36rpx;
			// 		font-weight: bold;
			// 		color: #FD9509;
			// 	}

			// 	.li {
			// 		&:nth-child(2) {
			// 			transform: translateY(-40rpx);

			// 			image {
			// 				width: 150rpx;
			// 				border-radius: 50%;
			// 			}
			// 		}
			// 	}
			// }
		}
	}
</style>